home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / O Boy / Source / AETE_da.cp < prev    next >
Text File  |  1996-06-21  |  20KB  |  746 lines

  1. /*
  2.     AETE_da.cp
  3.     © Bob Boylan 1996
  4.  
  5.     Revision History
  6.     MacHack 1996        initial creation
  7. */
  8. #include "debug.h"
  9.  
  10. #include "AETE_da.h"
  11. #include "AEBuild.h"
  12. #include "AppAEObj_pd.h"
  13. #include "ComputerAETE_da.h"
  14. #include "Helpers_ut.h"
  15.  
  16. #include <sstream>
  17. #include <ASRegistry.h>
  18. #include <UMemoryMgr.h>
  19. #include <algo.h>
  20.  
  21.  
  22.  
  23.  
  24. //    -----------------------------------------------------------------
  25. //    GetAstring ... handy for getting data out of the AETE
  26. //
  27. string
  28. GetAstring( istream &ioStream, Boolean inDoAlign );
  29. string
  30. GetAstring( istream &ioStream, Boolean inDoAlign = true )
  31. {
  32. UInt_8    theLen;
  33. char    theString[256];
  34.  
  35.     ioStream.read( &theLen,1 );
  36.     dassert( theLen >= 0 );
  37.     if( theLen > 0 )
  38.     {
  39.         ioStream.read( (unsigned char *)&theString, theLen );
  40.         if( (inDoAlign == true ) &&
  41.             ((theLen & 0x1)  == 0 ) )
  42.         {
  43.             UInt_8    theAlignByte;
  44.             ioStream.read( &theAlignByte,1 );
  45.         }
  46.     }
  47.     else
  48.     {    // zero len, but we need to align and the len takes one byte
  49.         if( inDoAlign == true )
  50.         {
  51.             UInt_8    theAlignByte;
  52.             ioStream.read( &theAlignByte,1 );
  53.         }
  54.     }
  55.     return string( theString, Int_32(theLen) );
  56. }
  57.     
  58. // ------------------------------------------------------------
  59. //    istream getter of comparison ops
  60. //
  61. istream& operator >> (istream &ioStream, ComparisonOp_da& outComparison)
  62. {
  63.     string theName = GetAstring( ioStream );
  64.     Int_32    theOPID;
  65.     ioStream.read( (unsigned char *)&theOPID, 4 );
  66.     string theDesc = GetAstring( ioStream );
  67.  
  68.     return ioStream;
  69. }
  70. // ------------------------------------------------------------
  71. //    istream getter of properties
  72. //
  73. istream& operator >> (istream &ioStream, Prop_da& outProp)
  74. {
  75.     outProp._Name = GetAstring( ioStream );
  76.     ioStream.read( (unsigned char *)&outProp._ID, 4 );
  77.     ioStream.read( (unsigned char *)&outProp._Class, 4 );
  78.     
  79.     string theDesc = GetAstring( ioStream );
  80.     Int_16    theFlags;
  81.     ioStream.read( (unsigned char *)&theFlags, 2 );
  82.  
  83.     return ioStream;
  84. }
  85. // ------------------------------------------------------------
  86. //    istream getter of elements (aka submodels)
  87. //
  88. istream& operator >> (istream &ioStream, Elem_da& outElem)
  89. {
  90.     ioStream.read( (unsigned char *)&outElem._ID, 4 );
  91.     {
  92.         Int_16    theFormCount;
  93.         ioStream.read( (unsigned char *)&theFormCount, 2 );
  94.         for( Int_16 theFormIndex = 1 ; theFormIndex <= theFormCount ; theFormIndex++ )
  95.         {
  96.             DescType    theForm;
  97.             ioStream.read( (unsigned char *)&theForm, 4 );
  98.         }
  99.     }
  100.     
  101.     return ioStream;
  102. }
  103. // ------------------------------------------------------------
  104. //    istream getter of enum values
  105. //
  106. istream& operator >> (istream &ioStream, EnumValue_da& outEnumValue)
  107. {
  108.     outEnumValue._Name = GetAstring( ioStream );
  109.     ioStream.read( (unsigned char *)&outEnumValue._ID, 4 );
  110.  
  111.     string    theDesc = GetAstring( ioStream );
  112.  
  113.     return ioStream;
  114. }
  115. // ------------------------------------------------------------
  116. //    istream getter of enums
  117. //
  118. istream& operator >> (istream &ioStream, Enum_da& outEnum)
  119. {
  120.     ioStream.read( (unsigned char *)&outEnum._ID, 4 );
  121.     {
  122.         Int_16    theValueCount;
  123.         ioStream.read( (unsigned char *)&theValueCount, 2 );
  124.         for( Int_16 theValueIndex = 1 ; theValueIndex <= theValueCount ; theValueIndex++ )
  125.         {
  126.             EnumValue_da    theValue;
  127.             ioStream >> theValue;
  128.             outEnum._Values.push_back( theValue );
  129.         }
  130.     }
  131.     return ioStream;
  132. }
  133. // ------------------------------------------------------------
  134. //    istream getter of classes
  135. //
  136. istream& operator >> (istream &ioStream, Class_da& outClass)
  137. {
  138.     outClass._Name = GetAstring( ioStream );
  139.     ioStream.read( (unsigned char *)&outClass._ID, 4 );
  140.  
  141.     string    theDesc = GetAstring( ioStream );
  142.     
  143.     {    // the properties
  144.         Int_16    thePropCount;
  145.         ioStream.read( (unsigned char *)&thePropCount, 2 );
  146.         for( Int_16 thePropIndex = 1 ; thePropIndex <= thePropCount ; thePropIndex++ )
  147.         {
  148.             Prop_da    theProp;
  149.             ioStream >> theProp;
  150.             outClass._Props.push_back( theProp );
  151.         }
  152.     }
  153.     
  154.     {    // the elements (sub models)
  155.         Int_16    theEleCount;
  156.         ioStream.read( (unsigned char *)&theEleCount, 2 );
  157.         for( Int_16 theEleIndex = 1 ; theEleIndex <= theEleCount ; theEleIndex++ )
  158.         {
  159.             Elem_da    theElem;
  160.             ioStream >> theElem;
  161.             outClass._Elems.push_back( theElem );
  162.         }
  163.     }
  164.  
  165.     return ioStream;
  166. }
  167. // ------------------------------------------------------------
  168. //    istream getter of event parameters
  169. //
  170. istream& operator >> (istream &ioStream, EventParam_da& outEventParam)
  171. {
  172.     outEventParam._Name = GetAstring( ioStream );
  173.     
  174.     DescType    theKeyWord;
  175.     ioStream.read( (unsigned char *)&theKeyWord, 4 );
  176.     DescType    theType;
  177.     ioStream.read( (unsigned char *)&theType, 4 );
  178.     
  179.     string theParamDesc = GetAstring( ioStream );
  180.  
  181.     Int_16    theParamFlags;
  182.     ioStream.read( (unsigned char *)&theParamFlags, 2 );
  183.     
  184.     return ioStream;
  185. }
  186. // ------------------------------------------------------------
  187. //    istream getter of events
  188. //
  189. istream& operator >> (istream &ioStream, Event_da& outEvent)
  190. {
  191.     outEvent._Name = GetAstring( ioStream, false );
  192.     string    theEventDesc = GetAstring( ioStream, false );
  193.     if( ((outEvent._Name.length() + theEventDesc.length() ) & 1 ) == 1 )
  194.     {
  195.         UInt_8    theAlignByte;
  196.         ioStream.read( &theAlignByte,1 );
  197.     }
  198.     
  199.     DescType    theEventClass;
  200.     ioStream.read( (unsigned char *)&theEventClass, 4 );
  201.     DescType    theEventID;
  202.     ioStream.read( (unsigned char *)&theEventID, 4 );
  203.     DescType    theReplyParam;
  204.     ioStream.read( (unsigned char *)&theReplyParam, 4 );
  205.  
  206.     string    theReplyDesc = GetAstring( ioStream );
  207.     
  208.     Int_16    theReplyFlags;
  209.     ioStream.read( (unsigned char *)&theReplyFlags, 2 );
  210.  
  211.     DescType    theParamType;
  212.     ioStream.read( (unsigned char *)&theParamType, 4 );
  213.  
  214.     string    theParamDesc = GetAstring( ioStream );
  215.     
  216.     Int_16    thePFlags;
  217.     ioStream.read( (unsigned char *)&thePFlags, 2 );
  218.  
  219.     {
  220.         Int_16    theAdditionalParamCount;
  221.         ioStream.read( (unsigned char *)&theAdditionalParamCount, 2 );
  222.         for( Int_16 theEParamIndex = 1 ; theEParamIndex <= theAdditionalParamCount  ; theEParamIndex++ )
  223.         {
  224.             EventParam_da    theEventParam;
  225.             ioStream >> theEventParam;
  226.             outEvent._Params.push_back( theEventParam );
  227.         }
  228.     }
  229.     return ioStream;
  230. }
  231. // ------------------------------------------------------------
  232. //    istream getter of suites
  233. //
  234. istream& operator >> (istream &ioStream, Suite_da& outSuite)
  235. {
  236.     outSuite._Name = GetAstring( ioStream, false );
  237.     string    theSuiteDescription = GetAstring( ioStream, false );
  238.     if( ((outSuite._Name.length() + theSuiteDescription.length() ) & 1 ) == 1 )
  239.     {
  240.         UInt_8    theAlignByte;
  241.         ioStream.read( &theAlignByte,1 );
  242.     }
  243.     {
  244.         Int_32    theSuiteID;
  245.         ioStream.read( (unsigned char *)&theSuiteID, 4 );
  246.         Int_16    theSuiteLevel;
  247.         ioStream.read( (unsigned char *)&theSuiteLevel, 2 );
  248.         Int_16    theSuiteVersion;
  249.         ioStream.read( (unsigned char *)&theSuiteVersion, 2 );
  250.  
  251.         {    // events
  252.             Int_16    theEventCount;
  253.             ioStream.read( (unsigned char *)&theEventCount, 2 );
  254.             for( Int_16 theEventIndex = 1 ; theEventIndex <= theEventCount ; theEventIndex++ )
  255.             {
  256.                 Event_da    theEvent;
  257.                 ioStream >> theEvent;
  258.                 outSuite._Events.push_back( theEvent );
  259.             }
  260.         }
  261.                 
  262.         {    // classes
  263.             Int_16    theClassCount;
  264.             ioStream.read( (unsigned char *)&theClassCount, 2 );
  265.             for( Int_16 theClassIndex = 1 ; theClassIndex <= theClassCount ; theClassIndex++ )
  266.             {
  267.                 Class_da    theClass;
  268.                 ioStream >> theClass;
  269.                 outSuite._Classes.push_back( theClass );
  270.             }
  271.         }
  272.  
  273.  
  274.         {    // comparison operators
  275.             Int_16    theComparisonCount;
  276.             ioStream.read( (unsigned char *)&theComparisonCount, 2 );
  277.             for( Int_16 theCompIndex = 1 ; theCompIndex <= theComparisonCount ; theCompIndex++ )
  278.             {
  279.                 ComparisonOp_da    theComp;
  280.                 ioStream >> theComp;
  281.                 outSuite._CompOps.push_back( theComp);
  282.             }
  283.         }
  284.  
  285.         {    // enumerations
  286.             Int_16    theEnumCount;
  287.             ioStream.read( (unsigned char *)&theEnumCount, 2 );
  288.             for( Int_16 theEnumIndex = 1 ; theEnumIndex <= theEnumCount ; theEnumIndex++ )
  289.             {
  290.                 Enum_da    theEnum;
  291.                 ioStream >> theEnum;
  292.                 outSuite._Enums.push_back( theEnum );
  293.             }
  294.         }
  295.  
  296.  
  297.     }
  298.     return ioStream;
  299. }
  300.  
  301.  
  302. //    -----------------------------------------------------------------
  303. //    AnyEnum_2_typeChar_Ptr - ae coercion handler from any enum to char
  304. //                           ... will find the char string associated with an enum
  305. //
  306. pascal
  307. OSErr
  308. AnyEnum_2_typeChar_Ptr( DescType inTypeCode, const void * indataPtr, Size indataSize, DescType intoType, Int_32 inhandlerRefcon, AEDesc *outresult );
  309. pascal
  310. OSErr
  311. AnyEnum_2_typeChar_Ptr( DescType inTypeCode, const void * indataPtr, Size indataSize, DescType intoType, Int_32 inhandlerRefcon, AEDesc *outresult )
  312. {
  313.  
  314.     Int_32     theEnumValue = (*((Int_32 *) indataPtr));
  315.  
  316.     AETE_da * theAETEP = (AETE_da *) inhandlerRefcon;    // refcon holds the aete object *
  317.     dassert( theAETEP != nil );
  318.     
  319.     string theEnumName = theAETEP->GetEnumName( theEnumValue );
  320.     
  321.     OSErr theRetVal = ::AECreateDesc(intoType, (Ptr) theEnumName.c_str(), theEnumName.length(), outresult );
  322.     
  323.     return theRetVal;
  324. }
  325. //    -----------------------------------------------------------------
  326. //    Boolean_2_typeChar_Ptr - ae coercion handler from boolean to char
  327. //
  328. pascal
  329. OSErr
  330. Boolean_2_typeChar_Ptr( DescType inTypeCode, const void * indataPtr, Size indataSize, DescType intoType, Int_32 inhandlerRefcon, AEDesc *outresult );
  331. pascal
  332. OSErr
  333. Boolean_2_typeChar_Ptr( DescType inTypeCode, const void * indataPtr, Size indataSize, DescType intoType, Int_32 inhandlerRefcon, AEDesc *outresult )
  334. {
  335. #pragma unused( inhandlerRefcon )
  336.  
  337.     Boolean     theValue = (*((Boolean *) indataPtr));
  338.     string        theValueAsString;
  339.     if( theValue )
  340.     {
  341.         theValueAsString = string("True");
  342.     }
  343.     else
  344.     {
  345.         theValueAsString = string("False");
  346.     }
  347.     OSErr theRetVal = ::AECreateDesc(intoType, (Ptr) theValueAsString.c_str(), theValueAsString.length(), outresult );
  348.     
  349.     return theRetVal;
  350. }
  351.  
  352.  
  353. //    ---------------------------------------------------------------------------------- AETE
  354.  
  355. //    -----------------------------------------------------------------
  356. //    ctor
  357. //
  358. AETE_da::AETE_da()
  359.     : _EnumHandlerUPP( nil ),
  360.       _BooleanHandlerUPP( nil )
  361.  
  362. {}
  363. //    -----------------------------------------------------------------
  364. //    ctor (with application object)
  365. //
  366. AETE_da::AETE_da( AppAEObj_pd *inApp )
  367.     : _EnumHandlerUPP( nil ),
  368.       _BooleanHandlerUPP( nil )
  369. {
  370.     Clone_ut<StAEDescriptor> theAETE = RetrieveFromApp( inApp );
  371.     if( (*theAETE).mDesc.descriptorType == typeNull )
  372.     {
  373.         // not really scriptable
  374.     }
  375.     else
  376.     {    // ok, we now have the data, need to make sense of it ...
  377.         //     we can get either a list or a single aete
  378.         if( (*theAETE).mDesc.descriptorType == typeAEList )
  379.         {
  380.         Int_32    theNItems;
  381.              // a list of aetes
  382.             ::AECountItems( &(*theAETE).mDesc, &theNItems );
  383.             for( Int_32 theIndex=1; theIndex<=theNItems; theIndex++ )
  384.             {
  385.                 {
  386.                 StAEDescriptor    theAETEItem;
  387.                 DescType        theType;
  388.                     OSErr anErr = AEGetNthDesc( &(*theAETE).mDesc, theIndex, 
  389.                                     typeWildCard, &theType, &theAETEItem.mDesc );
  390.                     StHandleLocker    theLock( theAETEItem.mDesc.dataHandle );
  391.                     IncorpAETE( theAETEItem.mDesc.dataHandle );
  392.                     
  393.                 }
  394.  
  395.             }
  396.         }
  397.         else
  398.         {
  399.         StHandleLocker    theLock( (*theAETE).mDesc.dataHandle );
  400.             IncorpAETE( (*theAETE).mDesc.dataHandle );
  401.         }
  402.         
  403.  
  404.  
  405.         {    // install the coercion handler
  406.             _EnumHandlerUPP = NewAECoercePtrProc( AnyEnum_2_typeChar_Ptr );
  407.             _BooleanHandlerUPP = NewAECoercePtrProc( Boolean_2_typeChar_Ptr );
  408.             // install it    
  409.         #if GENERATINGPOWERPC
  410.             OSErr theErr = AEInstallCoercionHandler( typeEnumerated, typeChar, _EnumHandlerUPP, (Int_32)this, false, false );
  411.                  theErr = AEInstallCoercionHandler( typeBoolean, typeChar, _BooleanHandlerUPP, (Int_32)this, false, false );
  412.         #else
  413.             OSErr theErr = AEInstallCoercionHandler( typeEnumerated, typeChar, (ProcPtr)_EnumHandlerUPP, (Int_32)this, false, false );
  414.                   theErr = AEInstallCoercionHandler( typeBoolean, typeChar, (ProcPtr)_BooleanHandlerUPP, (Int_32)this, false, false );
  415.         #endif
  416.         
  417.         }
  418.  
  419.     }
  420.  
  421.     // for optimization we have this 'last class' bookmark
  422.     ClassIterator_ut    theNullSet;
  423.     _LastClass = theNullSet;
  424.  
  425. }
  426. //    -----------------------------------------------------------------
  427. //    dtor
  428. //
  429. AETE_da::~AETE_da()
  430. {
  431.     // clean up the ae coercion handlers
  432.     if( _EnumHandlerUPP != nil )
  433.     {
  434.  
  435. #if GENERATINGPOWERPC
  436.         AERemoveCoercionHandler( typeEnumerated, typeChar, _EnumHandlerUPP, false );
  437.         AERemoveCoercionHandler( typeBoolean, typeChar, _BooleanHandlerUPP, false );
  438. #else
  439.         AERemoveCoercionHandler( typeEnumerated, typeChar, (ProcPtr)_EnumHandlerUPP, false );
  440.         AERemoveCoercionHandler( typeBoolean, typeChar, (ProcPtr)_BooleanHandlerUPP, false );
  441. #endif
  442.         DisposeRoutineDescriptor( _EnumHandlerUPP );
  443.         DisposeRoutineDescriptor( _BooleanHandlerUPP );
  444.         _EnumHandlerUPP = nil;
  445.         _BooleanHandlerUPP = nil;
  446.     }
  447. }
  448.     
  449. //    -----------------------------------------------------------------
  450. //    GetProperties ... associated with a given class
  451. //
  452. vector<Prop_da>
  453. AETE_da::GetProperties( const DescType inClassID )
  454. {
  455. vector<Prop_da>    theRetVal;
  456.     // quick exit check
  457.     if( (*_LastClass)._ID == inClassID )
  458.     {
  459.         theRetVal = (*_LastClass)._Props;
  460.     }
  461.     else
  462.     {    // search the list we have already parsed
  463.         ClassIterator_ut    theFirstClass( &_Suites );
  464.         ClassIterator_ut    theLastClass ( &_Suites,true );
  465.         Class_da            theClassWeWant;
  466.         theClassWeWant._ID = inClassID;
  467.         ClassIterator_ut theFoundItem = find( theFirstClass, theLastClass, theClassWeWant );
  468.     
  469.         if( theFoundItem != theLastClass )
  470.         {
  471.             _LastClass = theFoundItem;
  472.             theRetVal = (*_LastClass)._Props;
  473.         }
  474.     }
  475.     return theRetVal;
  476.  
  477. }
  478.  
  479. //    -----------------------------------------------------------------
  480. //    GetElements ... associated with a given class
  481. //
  482. vector<Elem_da>
  483. AETE_da::GetElements( const DescType inClassID )
  484. {
  485. vector<Elem_da>    theRetVal;
  486.  
  487.     // quick exit check
  488.     if( (*_LastClass)._ID == inClassID )
  489.     {
  490.         theRetVal = (*_LastClass)._Elems;
  491.     }
  492.     else
  493.     {
  494.         ClassIterator_ut    theFirstClass( &_Suites );
  495.         ClassIterator_ut    theLastClass ( &_Suites,true );
  496.         if( inClassID != cFinderProcess)
  497.         {    // with an object we look in it's element list
  498.             Class_da            theClassWeWant;
  499.             theClassWeWant._ID = inClassID;
  500.             ClassIterator_ut theFoundItem = find( theFirstClass, theLastClass, theClassWeWant );
  501.         
  502.             if( theFoundItem != theLastClass )
  503.             {
  504.                 _LastClass = theFoundItem;
  505.                 theRetVal = (*_LastClass)._Elems;
  506.             }
  507.         }
  508.         else
  509.         {    // with an 'application' we hand back all the class types
  510.             while( theFirstClass != theLastClass )
  511.             {
  512.                     Elem_da    theElem;
  513.                     theElem._ID = (*theFirstClass)._ID;
  514.                     theRetVal.push_back( theElem );
  515.                 ++theFirstClass;
  516.             }
  517.         }
  518.     }
  519.     return theRetVal;
  520. }
  521. //    -----------------------------------------------------------------
  522. //    GetEnumName ... search all enums for a given value
  523. //
  524. string
  525. AETE_da::GetEnumName( const DescType inEnumValue )
  526. {
  527. string    theRetVal;
  528.     
  529.     EnumValue_da    theValueWeWant;
  530.     theValueWeWant._ID = inEnumValue;
  531.     
  532.     pair< vector<EnumValue_da>::iterator,vector<EnumValue_da>::iterator> theFoundItem
  533.         = equal_range( _EnumMap.begin(), _EnumMap.end(), theValueWeWant );
  534.  
  535.     if( theFoundItem.first != _EnumMap.end() )
  536.     {
  537.         theRetVal = (*(theFoundItem.first))._Name;
  538.     }
  539.     else
  540.     {
  541.         theRetVal = As4CharString( inEnumValue );
  542.     }
  543.  
  544.     return theRetVal;
  545. }
  546.     
  547. //    -----------------------------------------------------------------
  548. //    GetClassName
  549. //
  550. string
  551. AETE_da::GetClassName( const DescType inClassID )
  552. {
  553. string theRetVal;
  554.  
  555.     ClassIterator_ut    theFirstClass( &_Suites );
  556.     ClassIterator_ut    theLastClass ( &_Suites,true );
  557.     Class_da            theClassWeWant;
  558.     theClassWeWant._ID = inClassID;
  559.     ClassIterator_ut theFoundItem = find( theFirstClass, theLastClass, theClassWeWant );
  560.  
  561.  
  562.     if( theFoundItem != theLastClass )
  563.     {
  564.         theRetVal = (*theFoundItem)._Name;
  565.     }
  566.     else
  567.     {    // hmmm ... the class wasn't there? must be an application 
  568.         if( inClassID == cFinderProcess )
  569.         {
  570.             theRetVal = string("App");
  571.         }
  572.         else
  573.         {    // if not, maybe the user can make some sense of it
  574.             theRetVal = As4CharString( inClassID );
  575.         }
  576.     }
  577.     return theRetVal;
  578. }
  579.  
  580. //    -----------------------------------------------------------------
  581. //    RetrieveFromApp ... get the 'aete' data from the application
  582. //
  583. Clone_ut<StAEDescriptor> 
  584. AETE_da::RetrieveFromApp( AppAEObj_pd *inApp )
  585. {
  586.     ostringstream    theStream( ios::in | ios::out );
  587.         theStream << "'----': 0"; // the lang code
  588.         OSErr theErr;
  589.         StAEDescriptor    theAppleEvent;
  590.         
  591.         // use gizmos to create the apple event
  592.          theErr = AEBuildAppleEvent( kASAppleScriptSuite, kGetAETE,
  593.                     inApp->GetAppAddrType(),
  594.                     inApp->GetAppAddr(),
  595.                     inApp->GetSizeofAppAddr(),
  596.                     kAutoGenerateReturnID, kAnyTransactionID,
  597.                     &theAppleEvent.mDesc, theStream.str().c_str() );
  598.         dassert( theErr == noErr );
  599.         
  600.         StAEDescriptor    theReplyAppleEvent;
  601.         // and off with it
  602.         theErr = AESend( &theAppleEvent.mDesc, &theReplyAppleEvent.mDesc, kAEWaitReply,
  603.                         kAENormalPriority, 61, nil, nil );    // timeout = 61
  604.  
  605.         // package up the return value
  606.         StAEDescriptor    *theResult = new StAEDescriptor;
  607.         Clone_ut<StAEDescriptor>    theRetVal( theResult );
  608.         if( theErr == noErr )
  609.         {
  610.             theErr = AEGetParamDesc( theReplyAppleEvent, keyDirectObject, typeWildCard, &theResult->mDesc );
  611.         }
  612.         
  613.         return theRetVal;
  614.  
  615. }
  616.  
  617.  
  618. //    -----------------------------------------------------------------
  619. //    IncorpAETE ... merge with existing data
  620. //
  621. void
  622. AETE_da::IncorpAETE( Handle inAETEHandle )
  623. {
  624.     StHandleLocker    theLock( inAETEHandle );
  625.  
  626.     istringstream    theStream( string((char *) *inAETEHandle, GetHandleSize(inAETEHandle) ), ios::in | ios::binary);
  627.     {
  628.         // read the up front stuff
  629.         char    theDummy[2];
  630.         theStream.read( theDummy, 2 ); // aete version
  631.         
  632.         theStream.read( theDummy, 2 ) ; // lang
  633.         theStream.read( theDummy, 2 ) ; // script
  634.         
  635.         
  636.         Int_16    theSuiteCount;
  637.         theStream.read( (char *) &theSuiteCount, 2 );
  638.         
  639.         for( Int_16 theIndex = 1 ; theIndex <= theSuiteCount ; theIndex ++ )
  640.         {
  641.             Suite_da    theNewSuite;
  642.             theStream >> theNewSuite;
  643.             _Suites.push_back( theNewSuite );
  644.             
  645.             
  646.             {    // update the enum map ... needed for quick access to the enum names
  647.                 vector<Enum_da>::iterator theEIter = theNewSuite._Enums.begin();
  648.                 while( theEIter != theNewSuite._Enums.end() )
  649.                 {
  650.                     vector<EnumValue_da>::iterator theEVIter = (*theEIter)._Values.begin();
  651.                     while( theEVIter != (*theEIter)._Values.end() )
  652.                     {
  653.                         _EnumMap.push_back( *theEVIter );
  654.                         ++theEVIter;
  655.                     }
  656.                     ++theEIter;
  657.                 }
  658.             }
  659.         }
  660.         sort( _EnumMap.begin(), _EnumMap.end() ); // for later binary search
  661.     }
  662.  
  663. }
  664.  
  665. // ---------------------------------------------------------------------------------------------
  666.  
  667. //    -----------------------------------------------------------------
  668. //    ClassIterator_ut ctor
  669. //
  670. AETE_da::ClassIterator_ut::ClassIterator_ut( vector<Suite_da> * inSuites, Boolean inPointToEnd )
  671.      : _SuitesP( inSuites ),
  672.        _SuiteIndex( 0 ),
  673.        _ClassIndex( 0 )
  674. {
  675.     dassert( inSuites != nil );
  676.     if( inPointToEnd == true )
  677.     {
  678.         _SuiteIndex = _SuitesP->size();
  679.     }
  680.     else
  681.     {    // could be the first suite doesn't have any classes
  682.         while( (_SuiteIndex < _SuitesP->size() )  &&
  683.                ((*_SuitesP)[_SuiteIndex]._Classes.size() == 0 ))
  684.         {
  685.             ++_SuiteIndex;
  686.         }
  687.  
  688.     }
  689. }
  690. //    -----------------------------------------------------------------
  691. //    != operator
  692. //
  693. Boolean 
  694. AETE_da::ClassIterator_ut::operator !=( const ClassIterator_ut & inOther )
  695. {
  696.     if( (_SuiteIndex == inOther._SuiteIndex) &&
  697.         (_ClassIndex == inOther._ClassIndex) )
  698.         return false;
  699.     else
  700.         return true;
  701. }
  702. //    -----------------------------------------------------------------
  703. //    ++ operator
  704. //
  705. AETE_da::ClassIterator_ut
  706. AETE_da::ClassIterator_ut::operator ++()
  707. {
  708.     dassert( _SuiteIndex < _SuitesP->size() );
  709.     dassert( _ClassIndex <= (*_SuitesP)[_SuiteIndex]._Classes.size() );
  710.     if( (_ClassIndex + 1) < (*_SuitesP)[_SuiteIndex]._Classes.size() )
  711.     {
  712.         ++_ClassIndex;
  713.     }
  714.     else
  715.     {
  716.         // see if this suite has any classes, if not then move on to the next one
  717.         ++_SuiteIndex;
  718.         while( (_SuiteIndex < _SuitesP->size() )  &&
  719.                ((*_SuitesP)[_SuiteIndex]._Classes.size() == 0 ))
  720.         {
  721.             ++_SuiteIndex;
  722.         }
  723.         _ClassIndex = 0;
  724.     }
  725.     return *this;
  726. }
  727.  
  728.     
  729. //    -----------------------------------------------------------------
  730. //    * operator
  731. //
  732. Class_da &
  733. AETE_da::ClassIterator_ut::operator *()
  734. {
  735.     if( _SuitesP == nil )
  736.     {
  737.         Class_da    theRetVal;
  738.         theRetVal._ID = typeNull;
  739.         return theRetVal;
  740.     }
  741.     else
  742.     {
  743.         return (*_SuitesP)[_SuiteIndex]._Classes[_ClassIndex];
  744.     }
  745. }
  746.